/**
 * 
 */
package com.ydy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.AdminToken;
import com.ydy.annotation.CheckFormRepeat;
import com.ydy.annotation.CtrlParam;
import com.ydy.annotation.StaffToken;
import com.ydy.controller.base.BaseController;
import com.ydy.model.Shop;
import com.ydy.service.shop.ShopService;
import com.ydy.utils.StringUtils;
import com.ydy.vo.other.BaseVo;
import com.ydy.vo.other.PageVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "shop", name = "店铺模块")
public class ShopController extends BaseController {

	@Autowired
	private ShopService shopService;

	@GetMapping(value = "list", name = "店铺展示列表")
	@ResponseBody
	public ResponseEntity<PageVo<Shop>> list(Shop shop, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(shop);
		PageVo<Shop> vo = shopService.list(shop, page, size);
		return ResponseEntity.ok(vo);
	}

	@AdminToken
	@GetMapping(value = "select", name = "管理员筛选店铺列表")
	@ResponseBody
	public ResponseEntity<PageVo<Shop>> select(Shop shop, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(shop);
		PageVo<Shop> vo = shopService.select(shop, page, size);
		return ResponseEntity.ok(vo);
	}

	@AdminToken
	@CheckFormRepeat
	@PostMapping(value = "save", name = "管理员保存店铺信息")
	@ResponseBody
	public ResponseEntity<Shop> save(Shop shop) {
		return ResponseEntity.ok(shopService.saveOrUpdate(shop, null));
	}

	@StaffToken
	@CheckFormRepeat
	@PostMapping(value = "saveByStaff", name = "店员保存店铺信息")
	@ResponseBody
	public ResponseEntity<Shop> saveByStaff(Shop shop) {
		return ResponseEntity.ok(shopService.saveOrUpdate(shop, getStaff()));
	}

	@AdminToken
	@CheckFormRepeat
	@PostMapping(value = "status", name = "管理员上下架店铺")
	@ResponseBody
	public ResponseEntity<BaseVo> status(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(shopService.status(id));
	}

	@AdminToken
	@CheckFormRepeat
	@DeleteMapping(value = "delete", name = "管理员删除店铺")
	@ResponseBody
	public ResponseEntity<BaseVo> delete(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(shopService.delete(id));
	}

	@AdminToken
	@GetMapping(value = "selectById", name = "管理员查看店铺详情")
	@ResponseBody
	public ResponseEntity<Shop> selectById(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(shopService.selectById(id));
	}
}